import net from '@/network/net.js';
import $ from 'jquery';
import store from '@/store/store.js';

let api = {
    'getList': '/app/service/v1/getList',
    'save': '/app/service/v1/save',
    'del': '/app/service/v1/del',
};

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function(data) {
        return $.param(data)
    }
}

let res = {

};

function getList(page, pageSize) {
    let p = new Promise(function(resolve, reject) {
        net.req.post(api.getList, {
            page: page,
            pageSize: pageSize,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

function save(id, customerService) {
    let p = new Promise(function(resolve, reject) {
        net.req.post(api.save, {
            id: id,
            customerService: customerService,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

function del(id) {
    let p = new Promise(function(resolve, reject) {
        net.req.post(api.del, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

export default {
    getList,
    save,
    del,
}
